package com.pan;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

/**
 * -PptToHtml
 * <p>
 * By:panpan.wang 2019年11月28日
 */
public class PptToHtml {
    public static void pptToHtml(String pptPath, String htmlPath) {
        ActiveXComponent offCom = new ActiveXComponent("PowerPoint.Application");
        try {
            offCom.setProperty("Visible", new Variant(true));
            Dispatch excels = offCom.getProperty("Presentations").toDispatch();
            Dispatch excel = Dispatch.invoke(excels, "Open", Dispatch.Method,
                    new Object[]{pptPath, new Variant(false),

                            new Variant(false)}, new int[1]).toDispatch();
            Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[]{
                    htmlPath, new Variant(12)}, new int[1]);
            Variant f = new Variant(false);
            Dispatch.call(excel, "Close");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            offCom.invoke("Quit", new Variant[]{});
        }
        System.out.println("转换完毕！");
    }

    public static void main(String[] args) {
        String paths = new String("I:\\testPPT.ppt");
        String savepaths = new String("I:\\PPTresult.html");
        pptToHtml(paths, savepaths);
    }
}
